import {
	Piece
} from "@/src/chess/Piece.js";
import init from "@/src/chess/Init.js";
import util from "@/src/util/Util.js"
import {
	rule
} from "@/src/chess/MoveRule.js";

// 获取当前棋子能走的所有点
let moveAblePoint = function(pieces, code) {
	let piece = util.getPiece(pieces, code);
	if (piece) {
		let pieceType = util.getPieceType(code);
		let finallRule = rule;
		return eval("finallRule." + pieceType + "(pieces,piece)");
	}
	return [];
}
let initData = function(reversal) {
	let initPieces = init();
	if(reversal){
		initPieces.red.forEach(red => red.coo[1] = 9 - red.coo[1]);
		initPieces.black.forEach(red => black.coo[1] = 9 - black.coo[1]);
	}
	return  {
		piecesRed : initPieces.red,
		piecesBlack : initPieces.black,
		allPieces : initPieces.red.concat(initPieces.black)
	};
}

export default {
	moveAblePoint,
	initData
}
